#!/usr/bin/python
#_*_coding:utf-8_*_

products = [
	['Iphone',4000],
	['Ipad',2000],
	['Tesla',800000],
	['Coffee',35],
	['Clothes', 500],
    ['Shoes', 800]
]

shop_list = []

def shopList(salary):
	while True:
		for index,p in enumerate(products):
			print index,p[0],p[1]
		choice = raw_input("请选择你要购买的商品序号:").strip()
		if choice.isdigit():
			choice = int(choice)
			p_price = products[choice][1]
			if p_price < salary:
				shop_list.append(products[choice])
				salary -= p_price
				print "你已将\033[31;1m%s\033[0m添加到购物车中,你的工资还剩余\033[31;1m%s\033[0m" %(products[choice][0],salary)
			else:
				print "\033[41;1m你的工资余额已不足以支付当前商品,请重新选择商品!\033[0m"

		elif choice == 'quit':
			print "==============shopping list=============="
			for k,v in enumerate(shop_list):
				print k,v
			print "你的工资余额为\033[41;1m%s\033[0m" % salary
			print "====================bye=================="
			break
		else:
			print "您是输入有误，请重新输入!"

while True:
	salary = raw_input("请输入你的工资收入:").strip()
	if salary.isdigit():
		salary = int(salary)
		shopList(salary)
		break
	else:
		print "您输入的工资收入格式有误,请确认你输入的工资收入为整数!"
	if salary == 'quit':
		print "程序即将退出!"
		break

